package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 目标：
 *
 * @author Ashely
 * @date 2024/6/8 20:08
 */
@Mapper
public interface SetmealMapper {
    @Select("select count(category_id) from setmeal where category_id=#{id} group by category_id")
    Integer countByCategoryId(Long id);

    Page<SetmealVO> page(SetmealPageQueryDTO spqd);
@Insert("insert into setmeal(category_id,name,price,status,description,image,create_time,update_time,create_user,update_user) " +
"values (#{categoryId},#{name},#{price},#{status},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})")
@Options(useGeneratedKeys = true, keyProperty = "id")
@AutoFill(value = OperationType.INSERT)
    void add(Setmeal setmeal);
@Select("select * from setmeal where id=#{id}")
    Setmeal selectById(Long id);
@Delete("delete from setmeal where id=#{id}")
    void deleteById(Long id);
@AutoFill(value = OperationType.UPDATE)
    void update(Setmeal setmeal);

    List<Setmeal> list(Setmeal setmeal);
@Select("select s.name,s.copies,d.image,d.description from setmeal_dish s left join dish d on s.dish_id = d.id where s.setmeal_id=#{setmealId}")
    List<DishItemVO> getDishItemById(Long setmealId);
@Select("select count(*) from setmeal where status = #{status}")
    Integer countStatus(Integer status);

}
